<template>
	<view>
		<navbar title="我的消息"></navbar>
		<view class="message-box" v-if="list.length > 0">
			<view class="message-list" v-for="(item, index) in list" :key="index">
				<view class="title fa.jcsb">
					<view class="fa">
						<image class="message-icon" src="../../static/message2.png" mode="" v-if="item.type == 0"></image>
						<image class="message-icon" src="../../static/message3.png" mode="" v-if="item.type == 1"></image>
						<view v-if="item.type == 0">平台通知</view>
						<view v-if="item.type == 1">订单提醒</view>
					</view>
					<view class="time">{{item.createTime}}</view>
				</view>
				<view class="content">{{item.content}}</view>
			</view>
		</view>
		<view class="nodata-box" v-if="nodata">
			<image class="nodata-img" src="../../static/nodata.png" mode=""></image>
			<view class="nodata-prompt">暂无消息~</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				count: 0,
				list: [],
				nodata: 0
			};
		},
		onLoad() {
			this.getList()
		},
		onPullDownRefresh() {
			this.page = 1
			this.count = 0
			this.list = []
			this.getList()
			setTimeout(() => {
				uni.stopPullDownRefresh()
			}, 1000)
		},
		onReachBottom() {
			if(this.list.length < this.count) {
				this.page++
				this.getList()
			}
		},
		methods: {
			getList() {
				this.api.noticeListFunc().then(res => {
					if(res.code == 200) {
						this.count = res.total
						this.list = this.page == 1 ? res.rows : this.list.concat(res.rows)
						this.nodata = this.list.length > 0 ? 0 : 1
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.message-box{
		padding: 20rpx 24rpx 10rpx;
		.message-list{
			margin-bottom: 20rpx;
			padding: 24rpx;
			border-radius: 20rpx;
			background-color: #fff;
			.message-icon{
				margin-right: 16rpx;
				width: 52rpx;
				height: 52rpx;
			}
			.time{
				font-size: 24rpx;
				color: #aaa;
			}
			.content{
				margin-top: 16rpx;
				padding-top: 16rpx;
				border-top: 2rpx solid #E6E6E6;
			}
		}
	}
</style>
